<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :dictMap="dictMapAsync"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      :labelWidth="75"
    ></Ht-search-form>


    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="regConfig"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="50" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog :title="title" center  :visible.sync="open" width="1024px" append-to-body :close-on-click-modal="false">
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="140px">
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="交易流水号" prop="id">
              <el-input v-model="detailForm.id" :disabled="true"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="记账标识" prop="cbflag">
              <el-select style="width: 100%;" v-model="detailForm.cbflag" placeholder="记账标识" :disabled="true">
                <el-option
                  v-for="dict in dictMap.CBFLAG"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="CPG日期" prop="vdate">
              <el-date-picker v-model="detailForm.vdate" style="width: 100%;" type="date" value-format="yyyyMMdd" :disabled="true"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="工作日期" prop="workdate">
              <el-date-picker v-model="detailForm.workdate" style="width: 100%;" type="date" value-format="yyyyMMdd" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="发起参与机构号" prop="indirectSender">
              <el-input v-model="detailForm.indirectSender" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发起参与机构名称" prop="indirectSendername">
              <el-input v-model="detailForm.indirectSendername" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="接收参与机构号" prop="indirectRecver">
              <el-input v-model="detailForm.indirectRecver" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接收参与机构名称" prop="indirectRecvername">
              <el-input v-model="detailForm.indirectRecvername" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="付款人开户行行号" prop="payerAccBrno">
              <el-input v-model="detailForm.payerAccBrno" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="付款人开户行行名" prop="payerAccBrname">
              <el-input v-model="detailForm.payerAccBrname" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="付款人账号" prop="payerActno">
              <el-input v-model="detailForm.payerActno" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="付款人户名" prop="payerName">
              <el-input v-model="detailForm.payerName" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="交易合同号" prop="txnContNo">
              <el-input v-model="detailForm.txnContNo" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="买入价币种" prop="buyPriceCurcd">
              <el-select style="width: 100%;" v-model="detailForm.buyPriceCurcd" placeholder="买入价币种" :disabled="true">
                <el-option
                  v-for="dict in dictMap.CURCD"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="买入价" prop="buyPrice">
              <ht-amount-input
                v-model="detailForm.buyPrice"
                placeholder="买入价"
              ></ht-amount-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="买入外汇币种" prop="buyNumCurcd">
              <el-select style="width: 100%;" v-model="detailForm.buyNumCurcd" placeholder="买入外汇币种" :disabled="true">
                <el-option
                  v-for="dict in dictMap.CURCD"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="买入外汇数" prop="buyNum">
              <ht-amount-input
                v-model="detailForm.buyNum"
                placeholder="买入外汇数"
              ></ht-amount-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <el-input type="textarea" v-model="detailForm.remarks" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="录入操作员" prop="mdTlrno">
              <el-input v-model="detailForm.mdTlrno" :disabled="true"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="录入时间" prop="mdTime">
              <el-date-picker
                style="width: 100%"
                v-model="detailForm.mdTime"
                value-format="yyyyMMddHHmmss"
                type="datetime"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="复核附言" prop="ckRemarks">
              <el-input type="textarea" v-model="detailForm.ckRemarks" maxlength="128" show-word-limit/>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="approve" v-loading.fullscreen.lock="loading">复 核</el-button>
        <el-button type="primary" @click="reject" v-loading.fullscreen.lock="loading">拒 绝</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPageMixin } from "@/libs/listPageMixin";

import { amountThousandsFormatter } from "@/utils/table_col_formatter";
import HtAmountInput from "@/views/components/HtAmountInput";
import {
  apiUrlConfigReviewQuery,
  pvpSettlementApplyInformationReviewApprvoe,
  pvpSettlementApplyInformationReviewReject,
} from "@/api/cnaps/hvps/143";

export default {
  name: "PVPSettlementApplyInformationReview",
  mixins: [listPageMixin],
  components: { HtAmountInput },
  data() {
    return {
      // 查询参数
      queryParams: {
        idSeqNo: undefined,
        vdate1: undefined,
        vdate2: undefined,
        workdate: undefined,
        workdate2: undefined,
      },
      loading: false,
      // 搜索
      formOptions: [],
      //
      searchFormDictList: ["TXN_STATUS","CBFLAG","CURCD",],
      // 列信息
      regConfig: apiUrlConfigReviewQuery,
      tableBindColumns: [
        { prop: 'id',   label: '交易流水号'},
        { prop: 'workdate',   label: '工作日期', type: 'date'},
        { prop: 'vdate',   label: 'CPG日期', type: 'date'},
        { prop: 'status',   label: '业务状态',  dictCode:'TXN_STATUS' },
        { prop: 'mdTlrno',   label: '录入操作员'},
        { prop: 'mdTime',   label: '录入时间', type: 'date'},
      ],
      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      detailForm: {

      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,

      rules: {
        buyPrice : {required: true,message: "请输入买入价", trigger: "blur"},
        buyNum : {required: true,message: "请输入买入外汇数", trigger: "blur"}
      },
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索
      {
        type: "dates",
        nameObj: {
          startTimeName: "vdate1",
          endTimeName: "vdate2",
        },
        defaultAttr: {
          size: "small",
          label: "CPG日期",
          placeholder: ["请输入CPG日期开始", "请输入CPG日期结束"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate",
          endTimeName: "workdate2",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作日期开始", "请输入工作日期结束"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
      {
        type: "input",
        prop: "idSeqNo",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "PVP结算申请信息报文复核明细";
      this.detailForm = row;
      this.$set(this.detailForm,'buyPrice','');
      this.$set(this.detailForm,'buyNum','');
      this.open = true;
    },
    //点击审核按钮
    approve: function () {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          pvpSettlementApplyInformationReviewApprvoe(this.detailForm)
            .then((response) => {
              this.loading = true;
              this.msgSuccess("复核成功");
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },

    //点击拒绝按钮
    reject() {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          pvpSettlementApplyInformationReviewReject(this.detailForm)
            .then((response) => {
              this.msgSuccess("拒绝成功");
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
  },
};
</script>
